package com.nf.health.app.adapter;

import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.nf.health.app.R;
import com.nf.health.app.models.Account;

import java.util.List;

/**
 * 账户绑定列表
 *
 * @author jiax
 */
public class AccountAdapter extends BaseAdapter {

    private List<Account> accounts;

    public AccountAdapter(List<Account> accounts) {
        this.accounts = accounts;
    }

    @Override
    public int getCount() {
        if (accounts != null) {
            return accounts.size();
        }
        return 0;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
        ViewHolder holder = ViewHolder.get(parent, convertView, R.layout.item_cancel_bind_account, position);
        Account account = accounts.get(position);
        if ("family".equals(account.getType())) {
            holder.setText(R.id.tv_account_key, "健管机账户:");
        }
        if ("simple".equals(account.getType())) {
            holder.setText(R.id.tv_account_key, "爱尚康账户:");
        }
        if ("oldMobile".equals(account.getType())) {
            holder.setText(R.id.tv_account_key, "老年手机账户:");
        }
        if ("doctor".equals(account.getType())) {
            holder.setText(R.id.tv_account_key, "医生账户:");
        }
        String nick = account.getNick();
        String phone = account.getCellphone();
        String num = account.getAccount();
        if (!TextUtils.isEmpty(nick)) {
            holder.setText(R.id.tv_account_value, nick);
        } else if (!TextUtils.isEmpty(phone)) {
            holder.setText(R.id.tv_account_value, phone);
        }else{
            holder.setText(R.id.tv_account_value, num);
        }
        TextView btn_cancel = holder.getView(R.id.btn_cancel);
        btn_cancel.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onClick(position, "");
                }
            }
        });
        return holder.getConvertView();
    }

    private OnMyClickListener listener;

    public void setMyOnClickListener(OnMyClickListener listener) {
        this.listener = listener;
    }
}
